<?php


abstract class BaseVideo extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $status_id;


	
	protected $user_id;


	
	protected $rating;


	
	protected $obj_type;


	
	protected $obj_id;


	
	protected $video_src;


	
	protected $video_type;


	
	protected $width;


	
	protected $height;


	
	protected $updated_at;


	
	protected $created_at;

	
	protected $collVideoI18ns;

	
	protected $lastVideoI18nCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

  
  protected $culture;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getStatusId()
	{

		return $this->status_id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getRating()
	{

		return $this->rating;
	}

	
	public function getObjType()
	{

		return $this->obj_type;
	}

	
	public function getObjId()
	{

		return $this->obj_id;
	}

	
	public function getVideoSrc()
	{

		return $this->video_src;
	}

	
	public function getVideoType()
	{

		return $this->video_type;
	}

	
	public function getWidth()
	{

		return $this->width;
	}

	
	public function getHeight()
	{

		return $this->height;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = VideoPeer::ID;
		}

	} 
	
	public function setStatusId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->status_id !== $v) {
			$this->status_id = $v;
			$this->modifiedColumns[] = VideoPeer::STATUS_ID;
		}

	} 
	
	public function setUserId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = VideoPeer::USER_ID;
		}

	} 
	
	public function setRating($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->rating !== $v) {
			$this->rating = $v;
			$this->modifiedColumns[] = VideoPeer::RATING;
		}

	} 
	
	public function setObjType($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->obj_type !== $v) {
			$this->obj_type = $v;
			$this->modifiedColumns[] = VideoPeer::OBJ_TYPE;
		}

	} 
	
	public function setObjId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->obj_id !== $v) {
			$this->obj_id = $v;
			$this->modifiedColumns[] = VideoPeer::OBJ_ID;
		}

	} 
	
	public function setVideoSrc($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->video_src !== $v) {
			$this->video_src = $v;
			$this->modifiedColumns[] = VideoPeer::VIDEO_SRC;
		}

	} 
	
	public function setVideoType($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->video_type !== $v) {
			$this->video_type = $v;
			$this->modifiedColumns[] = VideoPeer::VIDEO_TYPE;
		}

	} 
	
	public function setWidth($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->width !== $v) {
			$this->width = $v;
			$this->modifiedColumns[] = VideoPeer::WIDTH;
		}

	} 
	
	public function setHeight($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->height !== $v) {
			$this->height = $v;
			$this->modifiedColumns[] = VideoPeer::HEIGHT;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = VideoPeer::UPDATED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = VideoPeer::CREATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->status_id = $rs->getInt($startcol + 1);

			$this->user_id = $rs->getInt($startcol + 2);

			$this->rating = $rs->getInt($startcol + 3);

			$this->obj_type = $rs->getInt($startcol + 4);

			$this->obj_id = $rs->getInt($startcol + 5);

			$this->video_src = $rs->getString($startcol + 6);

			$this->video_type = $rs->getString($startcol + 7);

			$this->width = $rs->getInt($startcol + 8);

			$this->height = $rs->getInt($startcol + 9);

			$this->updated_at = $rs->getTimestamp($startcol + 10, null);

			$this->created_at = $rs->getTimestamp($startcol + 11, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 12; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Video object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(VideoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			VideoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(VideoPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

    if ($this->isNew() && !$this->isColumnModified(VideoPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(VideoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = VideoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += VideoPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collVideoI18ns !== null) {
				foreach($this->collVideoI18ns as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = VideoPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collVideoI18ns !== null) {
					foreach($this->collVideoI18ns as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = VideoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getStatusId();
				break;
			case 2:
				return $this->getUserId();
				break;
			case 3:
				return $this->getRating();
				break;
			case 4:
				return $this->getObjType();
				break;
			case 5:
				return $this->getObjId();
				break;
			case 6:
				return $this->getVideoSrc();
				break;
			case 7:
				return $this->getVideoType();
				break;
			case 8:
				return $this->getWidth();
				break;
			case 9:
				return $this->getHeight();
				break;
			case 10:
				return $this->getUpdatedAt();
				break;
			case 11:
				return $this->getCreatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = VideoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getStatusId(),
			$keys[2] => $this->getUserId(),
			$keys[3] => $this->getRating(),
			$keys[4] => $this->getObjType(),
			$keys[5] => $this->getObjId(),
			$keys[6] => $this->getVideoSrc(),
			$keys[7] => $this->getVideoType(),
			$keys[8] => $this->getWidth(),
			$keys[9] => $this->getHeight(),
			$keys[10] => $this->getUpdatedAt(),
			$keys[11] => $this->getCreatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = VideoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setStatusId($value);
				break;
			case 2:
				$this->setUserId($value);
				break;
			case 3:
				$this->setRating($value);
				break;
			case 4:
				$this->setObjType($value);
				break;
			case 5:
				$this->setObjId($value);
				break;
			case 6:
				$this->setVideoSrc($value);
				break;
			case 7:
				$this->setVideoType($value);
				break;
			case 8:
				$this->setWidth($value);
				break;
			case 9:
				$this->setHeight($value);
				break;
			case 10:
				$this->setUpdatedAt($value);
				break;
			case 11:
				$this->setCreatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = VideoPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setStatusId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUserId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setRating($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setObjType($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setObjId($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setVideoSrc($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setVideoType($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setWidth($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setHeight($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setUpdatedAt($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setCreatedAt($arr[$keys[11]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(VideoPeer::DATABASE_NAME);

		if ($this->isColumnModified(VideoPeer::ID)) $criteria->add(VideoPeer::ID, $this->id);
		if ($this->isColumnModified(VideoPeer::STATUS_ID)) $criteria->add(VideoPeer::STATUS_ID, $this->status_id);
		if ($this->isColumnModified(VideoPeer::USER_ID)) $criteria->add(VideoPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(VideoPeer::RATING)) $criteria->add(VideoPeer::RATING, $this->rating);
		if ($this->isColumnModified(VideoPeer::OBJ_TYPE)) $criteria->add(VideoPeer::OBJ_TYPE, $this->obj_type);
		if ($this->isColumnModified(VideoPeer::OBJ_ID)) $criteria->add(VideoPeer::OBJ_ID, $this->obj_id);
		if ($this->isColumnModified(VideoPeer::VIDEO_SRC)) $criteria->add(VideoPeer::VIDEO_SRC, $this->video_src);
		if ($this->isColumnModified(VideoPeer::VIDEO_TYPE)) $criteria->add(VideoPeer::VIDEO_TYPE, $this->video_type);
		if ($this->isColumnModified(VideoPeer::WIDTH)) $criteria->add(VideoPeer::WIDTH, $this->width);
		if ($this->isColumnModified(VideoPeer::HEIGHT)) $criteria->add(VideoPeer::HEIGHT, $this->height);
		if ($this->isColumnModified(VideoPeer::UPDATED_AT)) $criteria->add(VideoPeer::UPDATED_AT, $this->updated_at);
		if ($this->isColumnModified(VideoPeer::CREATED_AT)) $criteria->add(VideoPeer::CREATED_AT, $this->created_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(VideoPeer::DATABASE_NAME);

		$criteria->add(VideoPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setStatusId($this->status_id);

		$copyObj->setUserId($this->user_id);

		$copyObj->setRating($this->rating);

		$copyObj->setObjType($this->obj_type);

		$copyObj->setObjId($this->obj_id);

		$copyObj->setVideoSrc($this->video_src);

		$copyObj->setVideoType($this->video_type);

		$copyObj->setWidth($this->width);

		$copyObj->setHeight($this->height);

		$copyObj->setUpdatedAt($this->updated_at);

		$copyObj->setCreatedAt($this->created_at);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getVideoI18ns() as $relObj) {
				$copyObj->addVideoI18n($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new VideoPeer();
		}
		return self::$peer;
	}

	
	public function initVideoI18ns()
	{
		if ($this->collVideoI18ns === null) {
			$this->collVideoI18ns = array();
		}
	}

	
	public function getVideoI18ns($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseVideoI18nPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collVideoI18ns === null) {
			if ($this->isNew()) {
			   $this->collVideoI18ns = array();
			} else {

				$criteria->add(VideoI18nPeer::ID, $this->getId());

				VideoI18nPeer::addSelectColumns($criteria);
				$this->collVideoI18ns = VideoI18nPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(VideoI18nPeer::ID, $this->getId());

				VideoI18nPeer::addSelectColumns($criteria);
				if (!isset($this->lastVideoI18nCriteria) || !$this->lastVideoI18nCriteria->equals($criteria)) {
					$this->collVideoI18ns = VideoI18nPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastVideoI18nCriteria = $criteria;
		return $this->collVideoI18ns;
	}

	
	public function countVideoI18ns($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseVideoI18nPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(VideoI18nPeer::ID, $this->getId());

		return VideoI18nPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addVideoI18n(VideoI18n $l)
	{
		$this->collVideoI18ns[] = $l;
		$l->setVideo($this);
	}

  public function getCulture()
  {
    return $this->culture;
  }

  public function setCulture($culture)
  {
    $this->culture = $culture;
  }

  public function getTitle()
  {
    $obj = $this->getCurrentVideoI18n();

    return ($obj ? $obj->getTitle() : null);
  }

  public function setTitle($value)
  {
    $this->getCurrentVideoI18n()->setTitle($value);
  }

  public function getRemark()
  {
    $obj = $this->getCurrentVideoI18n();

    return ($obj ? $obj->getRemark() : null);
  }

  public function setRemark($value)
  {
    $this->getCurrentVideoI18n()->setRemark($value);
  }

  protected $current_i18n = array();

  public function getCurrentVideoI18n()
  {
    if (!isset($this->current_i18n[$this->culture]))
    {
      $obj = VideoI18nPeer::retrieveByPK($this->getId(), $this->culture);
      if ($obj)
      {
        $this->setVideoI18nForCulture($obj, $this->culture);
      }
      else
      {
        $this->setVideoI18nForCulture(new VideoI18n(), $this->culture);
        $this->current_i18n[$this->culture]->setCulture($this->culture);
      }
    }

    return $this->current_i18n[$this->culture];
  }

  public function setVideoI18nForCulture($object, $culture)
  {
    $this->current_i18n[$culture] = $object;
    $this->addVideoI18n($object);
  }

} 